package priv.yiyuan.example.design;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 文件读取适配器
 *
 * @author YiYuan
 * @data 2025/8/8
 * @apoNote
 */
public class FileReaderAdapter implements DataReader {

    private final LegacyFileReader legacyFileReader;

    private final String filePath;

    public FileReaderAdapter(LegacyFileReader legacyFileReader, String filePath) {
        this.legacyFileReader = legacyFileReader;
        this.filePath = filePath;
    }

    @Override
    public String read() throws IOException {
        byte[] bytes = legacyFileReader.readFileBytes(filePath);
        return new String(bytes, StandardCharsets.UTF_8);
    }

    @Override
    public String getSourceInfo() {
        return "File: " + filePath;
    }

}
